import java.util.Map;

import org.apache.storm.task.OutputCollector;
import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseRichBolt;
import org.apache.storm.tuple.Fields;
import org.apache.storm.tuple.Tuple;
import org.apache.storm.tuple.Values;

public class bolt1 extends BaseRichBolt {

    private static final long serialVersionUID = 886149197481637894L;
    private OutputCollector collector;

    public void prepare(Map stormConf, TopologyContext context,
                        OutputCollector collector) {
        this.collector = collector;
    }

    public void execute(Tuple input) {
        //获取数据同时进行简单的数据预处理
        String book_num = input.getStringByField("book_num");
        String book_type = input.getStringByField("book_type");
        String book_name=input.getStringByField("book_name").replaceAll("^\"|\"$", "");
        String book_press=input.getStringByField("book_press").replaceAll("^\"|\"$", "");
        collector.emit(new Values(book_name,book_num,book_type,book_press));
        collector.ack(input);
    }

    public void declareOutputFields(OutputFieldsDeclarer declarer) {
        declarer.declare(new Fields("book_name","book_num","book_type","book_press"));
    }
}